In [2]:
from pgmpy.factors import TabularCPD
In [7]:
ez_cpd = TabularCPD(variable = 'ez',
variable_card = 2,
values = [[0.99, 0.35, 0.15, 0.05],
[0.01, 0.65, 0.85, 0.95]],
evidence= ['nb', 'ch'],
evidence_card=[2, 2])
b_cpd = TabularCPD(variable = 'nb',
variable_card = 2,
values = [[0.5, 0.5]])
ch_cpd = TabularCPD(variable = 'ch',
variable_card = 2,
values = [[0.5, 0.5]])
In [8]:
from pgmpy.models import BayesianModel
model = BayesianModel([('nb', 'ez'), ('ch', 'ez')])
model.add_cpds(ez_cpd, b_cpd, ch_cpd)
In [9]:
from pgmpy.inference import VariableElimination
inf = VariableElimination(model)
In [12]:
%%timeit -n 1 -r 1
p_b = inf.query(variables=['nb'], evidence={'ez': 1, 'ch': 0})
print(p_b['nb'])
In [ ]: